<?php
/* @var $this BackendController */
/* @var $model User */
/* @var $form TActiveForm */
?>
<?php Yii::app()->clientScript->registerScript('user-form-script',"
    selectPack({sid:['role','active'],attr:['role','active']});

    $('a#avatarDownload').click(function(e){
            var userAvatar = $('input#User_avatar');
            userAvatar.click();
        });
        $('input#User_avatar').change(function(e){
            $('input#avatarField').val($(this).val());
        });
")?>
<div class="form" style="padding:5px">

<?php $form=$this->beginWidget('TActiveForm', array(
	'id'=>'user-form',
    'htmlOptions' =>array('enctype'=>"multipart/form-data" ),
    //'focus'=>array($model,'name'),

    // Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'afterValidate'=>'js:afterValidate',
        'validateOnSubmit'=>true,
        'validateOnType'=>true,
        'validateOnChange'=>true,
       // 'hideErrorMessage'=>true
    ),
)); ?>
    <div class="alert alert-info">
       <?php echo Yii::t('UserModule.base','Fields with')?><span class="required"> * </span> <?php echo Yii::t('UserModule.base','are required.')?>
    </div>

<?php if(!$model->isNewRecord):?>
    <div class="avatar">
        <?php echo $form->labelEx($model,'avatar',array('style'=>'margin-left:30px;')); ?>
        <?php echo CHtml::decode($model->getAvatar())?>
        <?php echo $form->error($model,'avatar'); ?>
    </div>
    <br />
<?php endif;?>

    <div class="input-group">
		<?php echo $form->labelTb($model,'name'); ?>
		<?php echo $form->textFieldTb($model,'name'); ?>
        <?php echo $form->error($model,'name',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>

    <div class="input-group">
		<?php echo $form->labelTb($model,'login'); ?>
		<?php echo $form->textFieldTb($model,'login'); ?>
		<?php echo $form->error($model,'login',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>

    <div class="input-group">
		<?php echo $form->labelTb($model,'email'); ?>
		<?php echo $form->textFieldTb($model,'email'); ?>
		<?php echo $form->error($model,'email',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>

<?php if($model->isNewRecord):?>
    <div class="input-group">
		<?php echo $form->labelTb($model,'password'); ?>
		<?php echo $form->passwordFieldTb($model,'password'); ?>
		<?php echo $form->error($model,'password',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>
<?php endif;?>

    <div class="well well-sm col-lg-12">
		<?php echo $form->labelEx($model,'role',array('class'=>'paddingLeft10')); ?>
		<?php echo $form->dropDownListTb($model,'role',$model->getRoleOptions(),array('id'=>'role')); ?>
		<?php echo $form->error($model,'role'); ?>
        <span class="well-into">
            <?php echo $form->labelEx($model,'active',array('class'=>'paddingLeft10')); ?>
            <?php echo $form->dropDownListTb($model,'active',$model->getActiveDropdownData(),array('id'=>'active')); ?>
            <?php echo $form->error($model,'active'); ?>
        </span>
	</div>

        <div class="input-group" >
            <?php echo $form->labelEx($model,'avatar',array('class'=>'input-group-btn paddingLeftRight6020')); ?>
            <?php echo $form->fileField($model,'avatar',array('style'=>'display:none')); ?>
            <?php echo CHtml::openTag('span',array('class'=>'input-group-btn'));?>
            <?php echo CHtml::openTag('a',array('id'=>'avatarDownload','class'=>'btn btn-primary'));?>
            <?php echo CHtml::tag('i',array('class'=>'glyphicon glyphicon-plus'),'')?>
            <?php echo Yii::t('UserModule.base','Browse')?>
            <?php echo CHtml::closeTag('a')?>
            <?php echo CHtml::closeTag('span');?>
            <?php echo $form->textField($model,'avatar',array('id'=>'avatarField','class'=>'form-control','readonly'=>'readonly','disabled'=>'disabled','style'=>'width:300px')); ?>
            <?php echo $form->error($model,'avatar',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
        </div>
    <div>
        <?php echo $form::cancelButtonTb('/user/backend/admin'); ?>
        <?php echo $form::submitButtonTb($model,array('class'=>'btn btn-success','data-icon'=>'glyphicon  glyphicon-floppy-save')); ?>
    </div>

<?php $this->endWidget(); ?>
</div><!-- form -->